package com.eastfair.venueservice.controller;

import com.alibaba.fastjson.JSONObject;
import com.eastfair.venueservice.dto.ServiceOrderDTO;
import com.eastfair.venueservice.entity.ReportVenueDrawingAudit;
import com.eastfair.venueservice.dto.ReportVenueDrawingAuditSaveDTO;
import com.eastfair.venueservice.dto.ReportVenueDrawingAuditUpdateDTO;
import com.eastfair.venueservice.dto.ReportVenueDrawingAuditPageQuery;
import com.eastfair.venueservice.service.ReportVenueDrawingAuditService;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import com.eastfair.boot.controller.SuperController;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.eastfair.echo.core.EchoService;
import com.eastfair.core.base.R;
import com.eastfair.venueservice.vo.ReportVenueDrawingAuditVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import com.eastfair.annotation.annotation.security.PreAuth;

import com.eastfair.boot.request.PageParams;
import com.eastfair.core.context.ContextUtil;

import javax.annotation.Resource;


/**
 * <p>
 * 前端控制器
 * 一键报馆图纸审核记录
 * </p>
 *
 * @author dq
 * @date 2022-09-07
 */
@Slf4j
@Validated
@RestController
@RequestMapping("/reportVenueDrawingAudit")
@Api(value = "ReportVenueDrawingAudit", tags = "一键报馆图纸审核记录")
@PreAuth(replace = "venueservice:reportVenueDrawingAudit:")
public class ReportVenueDrawingAuditController extends SuperController<ReportVenueDrawingAuditService, Long, ReportVenueDrawingAudit, ReportVenueDrawingAuditPageQuery, ReportVenueDrawingAuditSaveDTO, ReportVenueDrawingAuditUpdateDTO> {

    @Resource
    private EchoService echoService;

    @Resource
    private ReportVenueDrawingAuditService reportVenueDrawingAuditService;

    @Override
    public void handlerResult(IPage<ReportVenueDrawingAudit> page) {
        // 想让返回值实现自动回显，请将此行代码打开
        // echoService.action(page);
    }

    /**
     * Excel导入后的操作
     *
     * @param list
     */
    @Override
    public R<Boolean> handlerImport(List<Map<String, String>> list){
        List<ReportVenueDrawingAudit> reportVenueDrawingAuditList = list
                .stream()
                .map((map) -> ReportVenueDrawingAudit.builder().build())
                .collect(Collectors.toList());
        return R.success(baseService.saveBatch(reportVenueDrawingAuditList));
    }

    /**
     * 处理参数
     *
     * @param params 分页参数
     */
    @Override
    public void handlerQueryParams(PageParams<ReportVenueDrawingAuditPageQuery> params) {
        ReportVenueDrawingAuditPageQuery pageQuery = params.getModel();
        //分页处理
        if(ContextUtil.getProjectId()!=null){
            pageQuery.setProjectId(ContextUtil.getProjectId());
        }
    }

    /**
     * 图纸分类审核ID查询图纸列表VO.
     *
     * @param reportVenueDrawingCategoryAuditId the report venue drawing category audit id
     * @return the r
     */
    @ApiOperation("图纸分类审核ID查询图纸列表VO")
    @GetMapping("/reportVenueDrawingCategoryAuditId/{reportVenueDrawingCategoryAuditId}")
    public R<List<ReportVenueDrawingAuditVO>> queryByReportVenueDrawingCategoryAuditId(@PathVariable("reportVenueDrawingCategoryAuditId") Long reportVenueDrawingCategoryAuditId) {
        log.info("queryByReportVenueDrawingCategoryAuditId - 图纸分类审核ID查询图纸列表VO, reportVenueDrawingCategoryAuditId={}", reportVenueDrawingCategoryAuditId);
        List<ReportVenueDrawingAuditVO> list
                = reportVenueDrawingAuditService.listVOByReportVenueDrawingCategoryAuditId(reportVenueDrawingCategoryAuditId);
        return R.successDef(list);
    }

    /**
     * 订单下审核通过的图纸.
     *
     * @param serviceOrderDTO serviceOrderDTO
     * @return the r
     */
    @ApiOperation("订单下审核通过的图纸")
    @PostMapping("/queryDrawingOfPass")
    public R<Map<String,Object>> queryDrawingOfPass(@RequestBody ServiceOrderDTO serviceOrderDTO) {
        HashMap<String, Object> map = new HashMap<>(8);
        List<JSONObject> objects = new ArrayList<>();
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("imageUrl","www.baidu.com");
        jsonObject.put("imageName","图片1");
        objects.add(jsonObject);
        map.put("S1",objects);
        List<JSONObject> objects2 = new ArrayList<>();
        JSONObject jsonObject2 = new JSONObject();
        jsonObject2.put("imageUrl","www.qq.com");
        jsonObject2.put("imageName","图片2");
        objects2.add(jsonObject2);
        map.put("S2",objects2);
        return R.successDef(map);
    }
}
